#ifndef _CAN_DRIVER_H_
#define _CAN_DRIVER_H_
//limitation of can driver 
//1. we use standard frame only

#include "stm32f2xx.h"

#define CAN1_CLK             RCC_APB1Periph_CAN1
#define CAN1_RX_PIN          GPIO_Pin_8
#define CAN1_TX_PIN          GPIO_Pin_9
#define CAN1_GPIO_PORT       GPIOB
#define CAN1_GPIO_CLK        RCC_AHB1Periph_GPIOB
#define CAN1_AF_PORT         GPIO_AF_CAN1
#define CAN1_RX_SOURCE       GPIO_PinSource8
#define CAN1_TX_SOURCE       GPIO_PinSource9      

/* clock of CAN1 need to be enable to make CAN2 work*/
#define CAN2_CLK           RCC_APB1Periph_CAN1 | RCC_APB1Periph_CAN2
#define CAN2_RX_PIN        GPIO_Pin_12
#define CAN2_TX_PIN        GPIO_Pin_13
#define CAN2_GPIO_PORT     GPIOB
#define CAN2_GPIO_CLK      RCC_AHB1Periph_GPIOB
#define CAN2_AF_PORT       GPIO_AF_CAN2
#define CAN2_RX_SOURCE     GPIO_PinSource12
#define CAN2_TX_SOURCE     GPIO_PinSource13   

void can_gpio_config(CAN_TypeDef* can);
void can_baudrate_set(CAN_TypeDef* can, uint32_t baudrate);
void can_it_config(CAN_TypeDef* can, uint8_t preept, uint8_t sub);
void can_filter_config(CAN_TypeDef* can, uint32_t can_id);
void can_hardware_init(CAN_TypeDef* can, 
	uint32_t baudrate, 
	uint32_t filter_id, 
	uint32_t preept, 
	uint32_t sub);

#endif
